/**
 * 动态代理
 * 为每个类的每个方法添加一个日志功能
 * 使用Es6Proxy
 * 优点：感觉还是拦截到当前对象下
 * 缺点：
 */

import { GamePlayer } from "./ProxyStatic";
const proxyHandler = {
  get: function (_target: any, _prop: string) {
    if (typeof _target[_prop] === 'function') {
      const _func = _target[_prop]
      return function (_args: any) {
        _func.call(this, _args)
      }
    }
    return _target[_prop]
  }
};

const gamePlayer = new GamePlayer('张三')
const proxyGamePlayer = new Proxy(gamePlayer, proxyHandler)
proxyGamePlayer.login()
proxyGamePlayer.killBoss()
proxyGamePlayer.upgrade()
console.log('----------------');





